import spock.lang.Specification

/**
 * Created at 2018/1/10 15:35
 * @author gongweixin
 */
class StringExample extends Specification {

    def "sub"() {
        when:
        "123" == "123".substring(0, 5)

        then:
        thrown(StringIndexOutOfBoundsException)

        expect:
        "123" == "123".substring(0, 3)
        "12" == "123".substring(0, 2)
    }

    def "to Long"() {
        expect:
        123L == "123".toLong()
    }

    def "is number"() {
        expect:
        "123".isNumber()
        "12.3".isNumber()
        "0.3".isNumber()
        !"0.3a".isNumber()
        !"0.3.0".isNumber()
    }

    def "to BigDecimal"() {
        expect:
        123.0 == "123".toBigDecimal()
        12.3 == "12.3".toBigDecimal()
        0.3 == "0.3".toBigDecimal()
    }
}
